package com.linkit.main.article;

import android.annotation.SuppressLint;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.linkit.main.AbstractPage;
import com.linkit.main.ControllerId;
import com.linkit.main.MainActivity;
import com.linkit.main.R;
import com.linkit.model.Article;

/**
 * Hiện thị các tin tức mới nhất
 * 
 */
public class ArticleComments extends AbstractPage implements OnClickListener {

	private MainActivity main;
	private Article article;
	private WebView browser;

	public ArticleComments() {
		main = MainActivity.getInstance();
	}

	/**
	 * Hiện thị thông tin chi tiết của trang comment
	 * 
	 * @param article
	 */
	public void showPage(Article article) {

		this.article = article;

		showPages();
	}

	@Override
	public void setControllerId() {
		main.setControllerId(ControllerId.ARTICLES_COMMENT);
	}

	@Override
	public void showHeader() {

		main.setVisibleHeader(false);

	}

	@Override
	protected void setLayout() {
		// khởi tạo layout
		layout = (RelativeLayout) LinearLayout.inflate(main,
				R.layout.article_comment, null);

	}

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	public void showContent() {
		main.setOnBackPressedImpl(this);
		// khởi tạo param
		browser = (WebView) layout.findViewById(R.id.news_comment_webview);
		browser.setWebViewClient(new MyBrowser());
		browser.getSettings().setJavaScriptEnabled(true);
		browser.loadUrl(article.linkComments);

		// thêm nội dung vào danh sách tra cứu
		main.contentManager.addSubContentLayout(layout);

	}

	@Override
	public void onBackPressed() {
		main.contentManager.removeSubContentlayout();
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();

		switch (id) {
		case R.id.news_top_btn:
			break;
		}
	}

	private class MyBrowser extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}

}